<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 8, 2013
 */
    require('top.inc.php');
    $formLoad = new Form();
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1) {
    if(isset($_POST['addWarehouse'])) {
        $query = "INSERT INTO warehouses ( warehousename, warehouseaddress, customerdefinedname, inserteddate ) VALUES ( :warehousename, :warehouseaddress, :customerdefinedname, :inserteddate )";
        $query_params = array (
            ':warehousename' => $_POST['warehousename'],
            ':warehouseaddress' => $_POST['warehouseaddress'],
            ':customerdefinedname' => $_POST['customerdefinedname'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        if($result) {
            echo $msg['36'];
        }
    } else {
?>
<form class="form-horizontal" action="" method="post" id="addWarehouse">
    <div class="control-group">
        <label class="control-label" for="warehousename"><?php echo $warehouses['warehousename']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('warehousename', "span2", "", $warehouses['warehousename']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="warehouseaddress"><?php echo $warehouses['warehouseaddress']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textArea('warehouseaddress', 'span5', ""); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="customerdefinedname"><?php echo $warehouses['customerdefinedname']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('customerdefinedname', "span2", "", $warehouses['customerdefinedname']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputEmail">&nbsp;</label>
        <div class="controls"><input class="btn btn-primary" type="submit" value="Add Warehouse" name="addWarehouse" /></div>
    </div>
</form>
<?php
    }
} else {
    header("Location: login.php");
}
?>
<?php
    include ('bottom.inc.php');
?>